package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.OrderType;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.pattern.orderStatus.status.IOrderStatus;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class FreightPayListAdapter extends RecyclerArrayAdapter<OrderInfo> {
    private IOrderStatus iOrderStatus;

    public FreightPayListAdapter(Context context, IOrderStatus iOrderStatus) {
        super(context);
        this.iOrderStatus = iOrderStatus;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new FreightPayListViewHolder(parent, R.layout.item_freightpay_list);
    }

    private class FreightPayListViewHolder extends BaseViewHolder<OrderInfo> {

        private TextView orderNumberTextView;

        private LinearLayout freightLinearLayout;
        private TextView freightTextView;
        private TextView submitTextView;
        private TextView tv_chepai;
        private TextView tv_calculation;
        private TextView tv_dress;
//        private TextView tv_shenhe;

        private TextView tv_xiashou_num;
        private TextView tv_huoquan_num;


        public FreightPayListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            orderNumberTextView = getView(R.id.item_order_list_topLeftTextView);


            freightLinearLayout = getView(R.id.item_order_list_freightLinearLayout);
            freightTextView = getView(R.id.item_order_list_freightTextView);
            submitTextView = getView(R.id.item_order_list_submitTextView);
            tv_chepai = getView(R.id.tv_chepai);
            tv_calculation = getView(R.id.tv_calculation);
            tv_dress = getView(R.id.tv_dress);

            tv_xiashou_num = getView(R.id.tv_xiashou_num);
            tv_huoquan_num = getView(R.id.tv_huoquan_num);
//            tv_shenhe= getView(R.id.tv_shenhe);


//
//            //记录
//            addOnClickListener(R.id.tv_tonghua);
            addOnClickListener(R.id.item_order_list_submitTextView);
//            addOnClickListener(R.id.tv_shenhe);
        }

        @Override
        public void setData(OrderInfo data) {
            super.setData(data);

            try {

                if (iOrderStatus != null) {
                    if (!TextUtils.isEmpty(data.customername)){
                        tv_huoquan_num.setText("货权:"+data.customername);
                    }
                    if (null!=data.businessno&&!TextUtils.isEmpty(data.businessno)){
                        tv_xiashou_num.setVisibility(View.VISIBLE);
                        tv_xiashou_num.setText("销售单号："+data.businessno);
                    }else {
                        tv_xiashou_num.setVisibility(View.GONE);
                    }

                    //费用计算
                    if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_FREIGHT) {
                        submitTextView.setText("费用计算");
                        orderNumberTextView.setText(data.drivername);
                        tv_chepai.setText(data.vehiclenum);
                        tv_dress.setText(data.placecity+" "+data.placecounty+"->"+data.destinationcity+" "+data.destinationcounty);


                        if ("1".equals(data.iscount)){
                            freightTextView.setText("(已付金额：￥"+data.settleprice+")");
                            tv_calculation.setText("已计算");
                            submitTextView.setVisibility(View.INVISIBLE);
                        }else {
                            freightTextView.setText("(预计金额：￥"+data.totalprice+")");
                            tv_calculation.setText("未计算");
                            submitTextView.setVisibility(View.VISIBLE);
                        }

//                        if ("0".equals(data.fcremarks)){
//                            tv_shenhe.setVisibility(View.VISIBLE);
//                        }else {
//                            tv_shenhe.setVisibility(View.GONE);
//                        }

                    }

                    //付款申请
                    if (iOrderStatus.getOrderStatusType() == OrderType.TYPE_PAYMENT) {
                        submitTextView.setText("申请支付");
                        orderNumberTextView.setText(data.drivername);
                        tv_chepai.setText(data.vehiclenum);
                        tv_dress.setText(data.placecity+" "+data.placecounty+"->"+data.destinationcity+" "+data.destinationcounty);

                        freightTextView.setText("(预计金额：￥"+data.freightprice+")");
                        if ("1".equals(data.issettle)){
                            tv_calculation.setText("付款中");
                        }else if ("2".equals(data.issettle)){
                            tv_calculation.setText("已付款");
                        }else if ("3".equals(data.issettle)){
                            tv_calculation.setText("待付款");
                        }else {
                            tv_calculation.setText("未付款");
                        }

                    }

                }



            }catch (Exception e){
                Log.e("fei","list数据错误："+e.toString());
            }

        }
    }
}
